# 参考资料： [Python+OpenCV实现图像的傅里叶变换](https://blog.csdn.net/wumu720123/article/details/89930745)

import cv2
import numpy as np
import matplotlib.pyplot as plt

# numpy实现傅里叶变换
img = cv2.imread("scene.jpeg", 0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
result = 20*np.log(np.abs(fshift))

plt.subplot(221)
plt.imshow(img, cmap='gray')
plt.title('original')
plt.axis('off')

plt.subplot(222)
plt.imshow(result, cmap='gray')
plt.title('result')
plt.axis('off')

# opencv实现傅里叶变换
img = cv2.imread("scene.jpeg", 0)
dft = cv2.dft(np.float32(img), flags = cv2.DFT_COMPLEX_OUTPUT)
dftShift = np.fft.fftshift(dft)
result = 20 * np.log(cv2.magnitude(dftShift))

plt.subplot(223)
plt.imshow(img, cmap='gray')
plt.title('original')
plt.axis('off')

plt.subplot(224)
plt.imshow(result, cmap='gray')
plt.title('result')
plt.axis('off')

plt.show()
